/**
 * Copyright (c) 2012-2014, Yang Yang <cntototo@gmail.com>
 *
 * This software may be distributed under the terms of the New BSD License.
 * See README for more details.
 */

#ifndef OS_H
#define OS_H

#include "def.h"

typedef long os_time_t;

struct wfs_timeval {
	os_time_t sec;
	os_time_t usec;
};

enum wfs_internal_err
os_add_time(struct wfs_timeval *a, struct wfs_timeval *b,
		struct wfs_timeval *sum);

enum wfs_internal_err
os_add_time_val(struct wfs_timeval *time, os_time_t sec, os_time_t usec,
		struct wfs_timeval *sum);

void
os_free_time(struct wfs_timeval **tv);

enum wfs_internal_err
os_get_time(struct wfs_timeval *tv);

int
os_is_time_before(struct wfs_timeval *before, struct wfs_timeval *after);

int
os_is_time_populated(struct wfs_timeval *tv);

enum wfs_internal_err
os_new_time(struct wfs_timeval **tv);

void
os_sleep(os_time_t sec, os_time_t usec);

enum wfs_internal_err
os_time_till_now(struct wfs_timeval *before, struct wfs_timeval *diff);

enum wfs_internal_err
os_sub_time(struct wfs_timeval *minuend, struct wfs_timeval *subtrahend,
		struct wfs_timeval *diff);

enum wfs_internal_err
os_sub_time_val(struct wfs_timeval *time, os_time_t sec, os_time_t usec,
		struct wfs_timeval *diff);

#endif /* OS_H */
